package com.hzmall.service.impl;

import com.hzmall.common.ServerResponse;
import com.hzmall.dao.OrderMapper;
import com.hzmall.dao.ProductMapper;
import com.hzmall.dao.UserMapper;
import com.hzmall.service.IStatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service("statisticService")
public class StatisticService implements IStatisticService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private OrderMapper orderMapper;


    //统计信息
    public ServerResponse baseCount(){
        Integer userCount = this.userMapper.countUser();
        Integer productCount = this.productMapper.countProduct();
        Integer orderCount = this.orderMapper.countOrder();
        Map<String,Integer> resultMap = new HashMap<String, Integer>();
        resultMap.put("userCount", userCount);
        resultMap.put("productCount",productCount);
        resultMap.put("orderCount",orderCount);
        if (resultMap.isEmpty()){
            return ServerResponse.createByErrorMessage("出错啦");
        }
        return ServerResponse.createBySuccess(resultMap);
    }

}
